package com.wc.AlgoOJ_homework.AlgoOJ_BL3.J_扫雷;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

/**
 * @Author congge
 * @Date 2024/4/4 12:47
 * @description http://43.138.190.70:8888/p/528?tid=6602a77318e03a818a4bf04e
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 50010, M = (int) 1e6 + 7, X = (int) 1e9 + 7;
    // 开地址法记录hash
    static long[] h = new long[M];
    // 记录hash对应的id
    static int[] id = new int[M];
    // 查看这个雷是否被炸过了
    static boolean[] st = new boolean[N];
    // 存雷
    static Bomb[] a = new Bomb[N];

    static LinkedList<Bomb> aa = new LinkedList<>();
    //    static Queue<Bomb> q = new LinkedList<>();
    static int[] q = new int[N];
    static int hh, tt;
    static int n, m;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        int res = 0;
        Arrays.fill(h, -1);
        for (int i = 1; i <= n; i++) {
            a[i] = new Bomb(sc.nextInt(), sc.nextInt(), sc.nextInt());
            add(a[i].x, a[i].y, i);
        }
        for (int i = 1; i <= m; i++) {
            int x, y, r;
            x = sc.nextInt();
            y = sc.nextInt();
            r = sc.nextInt();
            for (int j = x - r; j <= x + r; j++) {
                for (int k = y - r; k <= y + r; k++) {
                    if ((long) (j - x) * (j - x) + (long) (k - y) * (k - y) <= (long) r * r) {
                        int key = find(j, k);
                        if (id[key] > 0 && !st[id[key]]) {
                            bfs(id[key]);
                        }
                    }
                }
            }
        }

        for (int i = 1; i <= n; i++) {
            // 保证重复的点加上
            int x = a[i].x;
            int y = a[i].y;
            int key = find(x, y);
            if (st[id[key]]) res++;
        }
        out.println(res);
        out.flush();
    }

    static void bfs(int pos) {
//        Queue<Integer> q = new LinkedList<>();
        hh = 1;
        tt = 0;
        q[++tt] = pos;
        st[pos] = true;
        while (hh <= tt) {
            int t = q[hh++];
            int x = a[t].x, y = a[t].y, r = a[t].r;
            for (int i = x - r; i <= x + r; i++) {
                for (int j = y - r; j <= y + r; j++) {
                    if ((long) (i - x) * (i - x) + (long) (j - y) * (j - y) <= (long) r * r) {
                        int key = find(i, j);
                        if (h[key] != -1 && !st[id[key]]) {
                            // 防止重复加入
                            st[id[key]] = true;
                            q[++tt] = id[key];
                        }
                    }
                }
            }
        }
    }

//    static void BL() {
//        n = sc.nextInt();
//        m = sc.nextInt();
//        for (int i = 1; i <= n; i++) {
//            aa.add(new Bomb(sc.nextInt(), sc.nextInt(), sc.nextInt()));
//        }
//        for (int i = 1; i <= m; i++) {
//            q.add(new Bomb(sc.nextInt(), sc.nextInt(), sc.nextInt()));
//        }
//        int res = 0;
//        while (!q.isEmpty()) {
//            Bomb t = q.poll();
//            Iterator<Bomb> it = aa.iterator();
//            while (it.hasNext()) {
//                Bomb s = it.next();
//                if (t.r >= Math.sqrt(Math.pow(t.x - s.x, 2) + Math.pow(t.y - s.y, 2))) {
//                    q.add(s);
//                    it.remove();
//                    res++;
//                }
//            }
//        }
//        out.println(res);
//    }


    static long getHash(int x, int y) {
        return (long) x * X + y;
    }

    // 开地址发法
    static int find(int x, int y) {
        long hs = getHash(x, y);
        int key = ((int) (hs % M) + M) % M;
        //
        while (h[key] != -1 && h[key] != hs) {
            key++;
            if (key == M) key = 0;
        }
        return key;
    }

    static void add(int x, int y, int idx) {
        int key = find(x, y);
        h[key] = getHash(x, y);
        if (id[key] == 0 || a[id[key]].r < a[idx].r)
            // 记录编号
            id[key] = idx;
    }

    static class Bomb {
        int x, y, r;

        Bomb(int x, int y, int r) {
            this.x = x;
            this.y = y;
            this.r = r;
        }
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
